package com.acyouzi.dj;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 17/9/12 22:39
 *
 * @author sunxu
 */
public class Main3 {
//  public static void main(String[] args) {
//    Scanner in = new Scanner(System.in);
//    int n =  in.nextInt();
//    int m =  in.nextInt();
//    int[] arr = new int[n];
//    for (int i = 0; i < n; i++) arr[i] = in.nextInt();
//    Arrays.sort(arr);
//    int res = 0;
//    int index = 0;
//    while (index < n && arr[index] == 1) index++;
//    for (int i = 0; i < m; i++) {
//      int tag = in.nextInt();
//      if (tag % arr[0] != 0) continue;
//      for (int j = n-1; j >= 0; j--) {
//        if (arr[j] <= tag) tag -= arr[j];
//      }
//      if (tag == 0) res ++;
//    }
//    System.out.println(res);
//  }
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n =  in.nextInt();
    int m =  in.nextInt();
    int[] arr = new int[n];
    int sum = 0;
    for (int i = 0; i < n; i++) {
      arr[i] = in.nextInt();
      sum += arr[i];
    }
    Arrays.sort(arr);
    int res = 0;
    int index = 0;
    while (index < n && arr[index] == 1) index++;
    for (int i = 0; i < m; i++) {
      int tag = in.nextInt();
      for (int j = 0; j < index; j++) {
        if (index < n && tag % arr[index] == 0) {
          break;
        }
        tag -= 1;
        sum -= 1;
      }
      if (tag % arr[index] != 0) continue;
      if (sum < tag) continue;
      res ++;
    }
    System.out.println(res);
  }
}
